package com.tuanzi.loan.business.service.commuser.impl;

import com.tuanzi.loan.business.entity.commuser.CommuserInfo;
import com.tuanzi.loan.business.repository.commuser.CommuserInfoRepository;
import com.tuanzi.loan.business.service.commuser.CommuserInfoService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.repository.JPAAuditRepository;
import com.tuanzi.loan.core.service.BaseAuditServiceImpl;
import com.tuanzi.loan.core.service.CommonServiceImpl;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.commuser.CommuserInfosearchRequest;
import com.tuanzi.loan.vo.response.commuser.CommuserInfoSearchResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class CommuserInfoServiceImpl  implements CommuserInfoService {

    @Autowired
    private CommuserInfoRepository commuserInfoRepository;

    @Autowired
    private CommuserInfoService service;


    @Override
    public Page<CommuserInfoSearchResponse> list(PageSearcher<CommuserInfosearchRequest> request) {
        return commuserInfoRepository.list(request.getSearchCondition(),request.getPageable());
    }

    @Override
    public List<CommuserInfo> findCommuserBymobnum(CommuserInfosearchRequest request) {
        return commuserInfoRepository.findCommuserBymobnum(request);
    }

    @Override
    public CommuserInfo saveOrUpdate(CommuserInfo commuserInfo) {
        if(commuserInfo.getIsavaliable()==1){
            commuserInfo.setIsavaliable(0);
        }else{
            commuserInfo.setIsavaliable(1);
        }
        return commuserInfoRepository.saveAndFlush(commuserInfo);
    }



    @Override
    public CommuserInfo findOne(Long id) {
        return commuserInfoRepository.findOne(id);
    }

//    @Override
//    public void updateIsavaliable(int isavaliable,Long id) {
//        if (isavaliable==1)
//            commuserInfoRepository.updateIsavaliable("0",id);
//        else
//            commuserInfoRepository.updateIsavaliable("1",id);
//    }

}
